<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ajax和jsonp</title>
    <link rel="shortcut icon" href="../lib/image/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" href="../lib/css/all.css">

</head>

<body>
    <div id="app"></div>
</body>
<script>

    function fn() {
        
        // ajax 上传文件
        let formData = new FormData();
        formData.append("file", file, Date.now() + '.png')
        $.ajax({
            url: "",
            type: 'POST',
            dataType: 'json',
            data: formData,
            cache: false,
            contentType: false,
            processData: false,
            success: function (res) {
                console.log(res)
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log(XMLHttpRequest)
                console.log(textStatus)
                console.log(errorThrown)
            }

        })

        // jsonp 传值 回调
        $.ajax({
            url: 'ip?key=NHLBZ-LRM6U-ER2VE-4RJPZ-VUFVH-27BED&output=jsonp&callback=fn1',
            type: "get",
            dataType: 'jsonp',
            jsonpCallback: 'fn1' //传一个函数名给它，这个函数里面填写的是数据
        })
            .done(function (data) {
                console.log(data);
            })

    }
</script>

</html>